#include <string>
#include <assert.h>
#include <iostream>
#include <time.h>
#include "lsmtree.h"
#include <vector>

int main() {
  clock_t start, end;
  VirtualR::LSMTree *tree = new VirtualR::LSMTree();
  bool flag = tree->file_open("data");
  if (!flag) {
    std::cout << "file open error" << std::endl;
  }
  std::string temp = "fdhhhhhhhhhertyudfghtyufghtyufghhhhhhs";
  std::string value = "sdlllllcfvtgbertytyguftyufrtgcrtvgcfvgllllllllllf";
  start = clock();
  for (uint32_t i = 1; i < 100000; i++) {
    std::string tmp = temp + std::to_string(i);
    std::string tmp_value = value + std::to_string(i);
    flag = tree->put(tmp, tmp_value);
    if (!flag) {
      std::cout << "put error. key: " << tmp << " value: " << tmp_value << std::endl;
      return 0;
    }
  }
  end = clock();
  std::cout << "insert 100000: " << end - start << std::endl;
  
  std::string value_get = "";
  uint32_t count = 0;
  start = clock();
  for (uint32_t i = 1; i < 100000; i++) {
    std::string tmp = temp + std::to_string(i);
    flag = tree->get(tmp, value_get);
    if (value_get != value + std::to_string(i)) {
      count++;
      std::cout << "pos" << i << " value_get: " << value_get << " value: " << value + std::to_string(i) << std::endl;
    }
    if (count >= 20) {
      return 0;
    }
  }
  end = clock();
  std::cout << "get 100000: " << end - start << std::endl;
}